#include "string.h"
#include <string>
using namespace std;


namespace wyx
{
	void teststring1()
	{
		string s1;
		cout << s1.c_str() << endl;


		string s2("hello wyx");
	

		string s3(s2);
		cout << s3.c_str() << endl;
		string s4 = s3;
		cout << s4.c_str() << endl;

		string s5 = "Hang on!";
		cout << s5.c_str() << endl;
	}

	void teststring2()
	{
		string s1("hello wyx");
		cout << s1.c_str() << endl;

		string s2("hello");
		string s3;

		cout << s2.c_str() << endl;
		cout << s3.c_str() << endl;
		s3 = s2 = s1;
		cout << s2.c_str() << endl;
		cout << s3.c_str() << endl;

	}

	void teststring3()
	{
		//string s1("hello wyx");
		const string s1("hello wyx");

		/*for (auto e : s1)
		{
			cout << e;
		}
		cout << endl;


		string::iterator it = s1.begin();
		while (it != s1.end())
		{
			cout << *it;
			++it;
		}
		cout << endl;*/
	
		for (size_t i = 0; i < s1.size(); ++i)
		{
			cout << s1[i];
		}
		cout << endl;

		/*for (size_t i = 0; i < s1.size(); ++i)
		{
			s1[i]++;
			cout << s1[i];
		}*/
		cout << endl;

	}

	void teststring4()
	{
		string s1("hello wyx");
		cout << s1.capacity() << endl;

		s1.reserve(8);
		cout << s1.capacity() << endl;

		s1.reserve(15);
		cout << s1.capacity() << endl;

		s1.reserve(20);
		cout << s1.capacity() << endl;

		s1.reserve(40);
		cout << s1.capacity() << endl;

		s1.reserve(200);
		cout << s1.capacity() << endl;

		cout << s1.c_str() << endl;
	}

	void teststring5()
	{
		string s1("hello wyx");
		cout << s1.c_str() << endl;

		char ch;
		while (cin >> ch)
		{
			//s1.push_back(ch);
			s1 += ch;
			cout << s1.c_str() << endl;
			cout << s1.size() << endl;
			cout << s1.capacity() << endl << endl;

		}

	}

	void teststring6()
	{
		string s1("uhyrfhgwgf");
		cout << s1.c_str() << endl;

		s1.resize(8, 'c');
		cout << s1.size() << endl;
		cout << s1.c_str() << endl;
		cout << s1.capacity() << endl << endl;

		s1.resize(20, 'c');
		cout << s1.size() << endl;
		cout << s1.c_str() << endl;
		cout << s1.capacity() << endl << endl;
	}

	void teststring7()
	{
		string s1("hello wyx");
		cout << s1.c_str() << endl;
		//s1.append("czl");
		s1 += " rnefuihrhfr riejgj";
		cout << s1.c_str() << endl;
		s1.clear();
		cout << s1.c_str() << endl;
		cout << s1.size() << endl;
		cout << s1.capacity() << endl << endl;

	}

	void teststring8()
	{
		/*string s1("hello world");
		string s2("hello");
		string s3 = s1;
		cout << (s1 > s2) << endl;
		cout << (s1 < s3) << endl;
		cout << (s1 > s3) << endl;
		cout << (s1 < s3) << endl;
		cout << (s1 == s2) << endl;
		cout << (s1 == s3) << endl;*/

		string s1("hello");
		string s2("hello");
		cout << (s1 == s2) << endl;

		s1 += '\0';
		s1 += " world";
		s2 += " world";

		cout << (s1 != s2) << endl;
		cout << (s1 > s2) << endl;
		cout << (s1 >= s2) << endl;
		cout << (s1 < s2) << endl;
		cout << (s1 <= s2) << endl;

	}

	void teststring9()
	{
		//string s1 = "https://legacy.cplusplus.com/reference/cstring/strstr/?kw=strstr";
		string s1 = "https://zhuanlan.zhihu.com/p/430224888";
		string sub1;
		string sub2;
		string sub3;

		size_t pos1 = s1.find("://");
		//cout << pos1 << endl;
		if (pos1 != string::npos)
		{
			sub1 = s1.substr(0, pos1);
			cout << sub1.c_str() << endl;
		}

		size_t pos2 = s1.find('/', pos1 + 3);
		//cout << pos2 << endl;
		if (pos2 != string::npos)
		{
			sub2 = s1.substr(pos1 + 3, pos2 - (pos1 + 3));
			cout << sub2.c_str() << endl;
		}

		if (pos2 != string::npos)
		{
			sub3 = s1.substr(pos2);
			cout << sub3.c_str() << endl;
		}

	}

	void teststring10()
	{
		string s1("hello world");

		s1.insert(6, " wyx ");
		cout << endl << s1.c_str() << endl;


		s1.insert(s1.begin() + 6, 'y');
		cout << endl << s1.c_str() << endl;

		s1.erase(3,2);
		cout << endl << s1.c_str() << endl;

	}

	void teststring11()
	{
		string s1 = "hello wolrd";

		string::iterator it = s1.begin();
		while (it != s1.end())
		{
			if (*it == 'l')
			{
				it = s1.erase(it);
			}
			else
			{
				++it;
			}
		}

		s1 += " hello GUTE ";
		//s1 += 'g';
		s1 += " wyx";

		cout << s1 << endl;
		//cout <<  s1.c_str() << endl;

	}
}

int main()
{
	wyx::teststring11();

	/*string s1("uhyrfhgwgf");
	cout << s1 << endl;

	s1.resize(8, 'c');
	cout << s1.c_str() << endl;
	cout << s1 << endl;
	s1.resize(20, 'c');
	cout << s1.c_str() << endl;
	cout << s1 << endl;*/

	/*cout << endl;

	string s1("hello");
	string s2("hello");

	cout << (s1 == s2) << endl;

	s1 += '\0';
	s1 += " world";
	s2 += " world";

	cout << (s1 != s2) << endl;
	cout << (s1 > s2) << endl;
	cout << (s1 >= s2) << endl;
	cout << (s1 < s2) << endl;*/

	/*size_t size = strlen(nullptr);
	cout << size << endl;*/

	////string s1 = "https://legacy.cplusplus.com/reference/cstring/strstr/?kw=strstr";
	//string s1 = "https://wyx.com/xxx/yyyyy/zzzz";

	//string sub1;
	//string sub2;
	//string sub3;

	//size_t pos1 = s1.find("://");
	//cout << pos1 << endl;
	//if (pos1 != string::npos)
	//{
	//	sub1 = s1.substr(0, pos1);
	//	cout << sub1<< endl;
	//}

	//size_t pos2 = s1.find('/', pos1 + 3);
	//cout << pos2 << endl;
	//if (pos1 != string::npos)
	//{
	//	sub2 = s1.substr(pos1 + 3, pos2 - pos1 - 3);
	//	cout << sub2 << endl;
	//}
	return 0;
}
